/**
 * 
 */
package com.tocea.formation.users;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.tocea.formation.books.BookDAO;
import com.tocea.formation.books.BookImpl;
import com.tocea.formation.books.IBook;
import com.tocea.formation.connection.ConnectionManager;

/**
 * @author AKWilson
 *
 */
public class UserDAOTest {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		ConnectionManager.getConnectionManager();
	}

	/**
	 * Test method for {@link com.tocea.formation.users.UserDAO#add(com.tocea.formation.users.IUser)}.
	 */
	@Test
	public final void testAdd() {
		Integer result = UserDAO.add(new UserImpl(0, "Added", "Added"));
		assertEquals(result.toString(), Integer.toString(1) );
	}

	/**
	 * Test method for {@link com.tocea.formation.users.UserDAO#update(com.tocea.formation.users.IUser)}.
	 */
	@Test
	public final void testUpdate() {
		Integer result = UserDAO.update(new UserImpl(2, "kevin", "Updated"));
		IUser user = UserDAO.get(2);
		assertEquals(user.getpassword(), "Updated");
	}

	/**
	 * Test method for {@link com.tocea.formation.users.UserDAO#get(java.lang.Integer)}.
	 */
	@Test
	public final void testGet() {
		IUser u = UserDAO.get(1);
		assertEquals(u.getName(), "joan");
	}
	
	/**
	 * Test method for {@link com.tocea.formation.users.UserDAO#get(java.lang.Integer)}.
	 */
	@Test
	public final void testGetAll() {
		List<UserImpl> u = UserDAO.getAll();
		assertEquals((Integer)u.size(), UserDAO.nbUsers());
	}

}
